//
//  LSZSpecialPackaging.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/19.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZSpecialPackaging.h"
//#import "JKSongsMessStatus.h"
//#import "LCPlaylist.h"
//#import "NetworkTool+LCAVPlay.h"
//#import <WXApi.h>
#import <Reachability.h>

@implementation LSZSpecialPackaging
#pragma mark - 在view上 任意话一条线自定义颜色
+(id)addThreadWithOtherRGB:(UIView *)view A:(NSInteger)A B:(NSInteger)B C:(NSInteger)C D:(NSInteger)D R:(NSInteger)R G:(NSInteger)G BB:(NSInteger)BB
{
    //    添加下边边的边框
    CALayer *layer2 = [CALayer layer];
    layer2.frame = CGRectMake(A,B,C,D);
    layer2.backgroundColor = RGBColor(R,G,BB).CGColor;
    [view.layer addSublayer:layer2];
    return view;
}
#pragma mark - 时间戳的转换
+(NSString *)TimeStamp:(NSString *)strTime
{
    NSInteger fen = [strTime integerValue]/60000;
    NSInteger miao = [strTime integerValue]%60000/1000;
    NSString * timeStr = [[NSString alloc]init];
     if (fen<10) {
         if (miao<10) {
             timeStr = [NSString stringWithFormat:@"0%zd:0%zd", fen,miao];
         }else
         timeStr = [NSString stringWithFormat:@"0%zd:%zd", fen,miao];
     }else{
         if (miao<10) {
             timeStr = [NSString stringWithFormat:@"%zd:0%zd", fen,miao];
         }else
             timeStr  = [NSString stringWithFormat:@"%zd:%zd", fen,miao];
     }
    return timeStr;
}
#pragma mark - 获取之前的时间和现在的比  GetTime 2017-10-30 12:04:07
+(NSString *)GetThePreviousTimeAndCompareItNow:(NSString *)GetTime
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *timeDate = [dateFormatter dateFromString:GetTime];
    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:timeDate];
    long temp = 0;
    NSString *resultTime = [[NSString alloc]init];
    if (timeInterval/60 < 1) {
        resultTime = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        resultTime = [NSString stringWithFormat:@"%zd分钟前",temp];
    }
    else if((temp = temp/60) <24){
        resultTime = [NSString stringWithFormat:@"%zd小时前",temp];
    }
    else if((temp = temp/24) <30){
        resultTime = [NSString stringWithFormat:@"%zd天前",temp];
    }
    else if((temp = temp/30) <12){
        resultTime = [NSString stringWithFormat:@"%zd月前",temp];
    }
    else{
        temp = temp/12;
        resultTime = [NSString stringWithFormat:@"%zd年前",temp];
    }
    return resultTime;
}
#pragma mark - 获取当前月
+(NSString *)GetTheCurrentMonth
{
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获取当前日期
    NSDate* dt = [NSDate date];
    // 定义一个时间字段的旗标，指定将会获取指定年、月、日、时、分、秒的信息
    unsigned unitFlags = NSCalendarUnitMonth;
    // 获取不同时间字段的信息
    NSDateComponents* comp = [gregorian components: unitFlags
                                          fromDate:dt];
    NSString * month = [NSString stringWithFormat:@"%zd",comp.month];
    return  month;
}
#pragma mark - 获取当前时间
+(NSString *)GetTheCurrentMonthDay
{
    
    NSDate *senddate = [NSDate date];
    
    NSLog(@"date1时间戳 = %zd",time(NULL));
    NSString *date2 = [NSString stringWithFormat:@"%zd", (long)[senddate timeIntervalSince1970]];
    NSLog(@"date2时间戳 = %@",date2);
     NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *date1 = [dateformatter stringFromDate:senddate];
    NSLog(@"%@<><>",date1);
    return date1;
//    NSCalendar *gregorian = [[NSCalendar alloc]
//                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
//    // 获取当前日期
//    NSDate* dt = [NSDate date];
//    // 定义一个时间字段的旗标，指定将会获取指定年、月、日、时、分、秒的信息
//    unsigned unitFlags = NSCalendarUnitMonth;
//    // 获取不同时间字段的信息
//    NSDateComponents* comp = [gregorian components: unitFlags
//                                          fromDate:dt];
//    NSString * month = [NSString stringWithFormat:@"%zd-%@",comp.month,comp.date];
//    return  month;
}
#pragma mark - 热文时间
+(NSString *)hotTime:(NSString *)time
{
    if([time rangeOfString:@" "].location !=NSNotFound)
    {
        NSArray *array = [time componentsSeparatedByString:@" "]; //从字符A中分隔成2个元素的数组
        NSString * strTime = [NSString stringWithFormat:@"%@",array[1]];
        
        
        if([time rangeOfString:@":"].location !=NSNotFound)
        {
            NSArray *arrayTwo = [strTime componentsSeparatedByString:@":"]; //从字符A中分隔成2个元素的数组
            NSString * timeStr = [[NSString alloc]initWithFormat:@"%@:%@",arrayTwo[0],arrayTwo[1]];
            return timeStr;
        }
        else{
            return strTime;
        }
    }
    return time;
}







//+(NSString *)addPlaylistWithArrayData:(NSArray *)arrayData
//{
//    JKSongsMessResult * results = [[JKSongsMessResult alloc] init];
//     NSArray *arr = [NSArray yy_modelArrayWithClass:[JKSongsMessStatus class] json:arrayData];
//    results.data = arr;
//    LCPlaylist *playlist = [LCPlaylist new];
//    playlist.name = @"playlist01";
//    for (JKSongsMessStatus *songDictionary in arr)
//    {
//        songDictionary.filePath = [NSString stringWithFormat:@"%@", [kNetworkTool mp3WithUrl:songDictionary.fileUrl]];//歌曲文件
//        [playlist addSong:songDictionary];
//    }
//    [_PlaylistMgr removeAllPlaylists];
//    [_PlaylistMgr addPlaylist:playlist];
//    //这个明天做
//    NSString * Strva = [NSString stringWithFormat:@"%@",_LCPlayer.valueDistinguish];
//    NSString * strValue = [NSString stringWithFormat:@"%@",NullStringjudgment(Strva)];
//    return strValue;
//}
/*
#pragma mark - 分享
+(void)shareShengJingMessageWithViewController:(UIViewController *)viewController
                                    imageArray:(NSArray *)imageArray
                                      url:(NSString *)url
                                         title:(NSString *)title
                                contentMessage:(NSString *)messageBody
                                          type:(SSDKContentType)type{
         //1、创建分享参数
    if (imageArray) {
        
    }else{
        imageArray = @[[UIImage imageNamed:@"placeholder"]];
    }
    if (url) {
        
    }else{
        url = @"http://www.9ku.com/down/fuyin/pc/";
    }
         if (title) {
            //
            NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
            [shareParams SSDKSetupShareParamsByText:messageBody
                                             images:imageArray
                                                url:[NSURL URLWithString:url]
                                              title:title
                                               type:type];
            //            //2、分享（可以弹出我们的分享菜单和编辑界面）
             [[NSOperationQueue mainQueue] addOperationWithBlock:^{//-[UIApplication canOpenURL:] must be used from main thread only
                
                [ShareSDK showShareActionSheet:nil items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                    
                    switch (state) {
                        case SSDKResponseStateSuccess:
                        {
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"分享成功"
                                                                                           message:nil
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                                                  handler:^(UIAlertAction * action) {}];
                            
                            [alert addAction:defaultAction];
                            
                            [viewController presentViewController:alert animated:YES completion:nil];
                            break;
                        }
                        case SSDKResponseStateFail:
                        {
                            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"分享失败"
                                                                                           message:[NSString stringWithFormat:@"%@",error]
                                                                                    preferredStyle:UIAlertControllerStyleAlert];
                            
                            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                                                  handler:^(UIAlertAction * action) {}];
                            
                            [alert addAction:defaultAction];
                            [viewController presentViewController:alert animated:YES completion:nil];
                            break;
                        }
                        default:
                            break;
                    }
                    
                }];
                 
             }];
        }
}

*/
+(void)shareWXWithViewController:(NSString *)url title:(NSString *)title type:(int)type
{
    WXMediaMessage *message = [WXMediaMessage message];
    message.title = @"九酷云音乐";
    message.description = title;
    [message setThumbImage:[UIImage imageNamed:@"分享图片"]];
    
    WXVideoObject *ext = [WXVideoObject object];
    ext.videoUrl = url;
    message.mediaObject = ext;
    
    SendMessageToWXReq * resp = [[SendMessageToWXReq alloc] init];
    resp.message = message;
    resp.bText = NO;
    resp.scene = type;
    [WXApi sendReq:resp];

//     [WXApi sendResp:resp];
    
//    WXMediaMessage * message = [WXMediaMessage message];
//    message.title = @"标题";
//    message.description = @"描述";
//    [message setThumbImage:[UIImage imageNamed:@"title"]];
//
//    WXVideoObject * videoObject = [WXVideoObject object];
//    videoObject.videoUrl = url;
//    videoObject.videoLowBandUrl = videoObject.videoUrl;
//
//
//    SendMessageToWXReq * req = [[SendMessageToWXReq alloc]init];
//    req.bText = NO;
//    req.message = message;
////    req.scene = WXSceneSession;//
//    req.scene = type;
//    [WXApi sendReq:req];
    
//    WXMediaMessage *message = [WXMediaMessage message];
//    // 标题
//    message.title = @"标题";//@"音乐标题";
//    // 描述内容
//    message.description = messageBody;//@"音乐描述";
//    [message setThumbImage:[UIImage imageNamed:@"placeholder"]];
//
//    // 多媒体消息中包含的音乐数据对象
//    WXMusicObject *ext = [WXMusicObject object];
//    // 音乐网页的url地址
//    ext.musicUrl = url;//@"音乐url";
//    // 音乐lowband数据url地址
//    ext.musicLowBandDataUrl = ext.musicUrl;
//    // 音乐数据url地址
//    ext.musicDataUrl = url;//@"音乐数据url";
//    // 音乐lowband数据url地址
//    ext.musicLowBandDataUrl = ext.musicDataUrl;
//    message.mediaObject = ext;
//
//    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
//    req.bText = NO;
//    req.message = message;
//    req.scene = type;
//
//    [WXApi sendReq:req];
}
//网页
+(void)shareWXWithWebPage:(NSString *)url title:(NSString *)title type:(int)type
{
    WXMediaMessage * message = [WXMediaMessage message];
    message.title = title;
    message.description = @"云头条";
    [message setThumbImage:[UIImage imageNamed:@"分享图片"]];
    WXWebpageObject * web = [WXWebpageObject object];
    web.webpageUrl = url;
    message.mediaObject = web;
    SendMessageToWXReq * req = [[SendMessageToWXReq alloc]init];
    req.bText = NO;
    req.message = message;
    req.scene = type;
    [WXApi sendReq:req];
}
#pragma mark - 判断手机号
+ (BOOL)isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[0-9])|(147)|(148)|(198)|(146)|(166)|(174)|(199)|(17[0-9])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}
#pragma mark - 判断有没有网络
+ (void)Reachability:(strNetwork)block
{
    Reachability *reach = [Reachability reachabilityWithHostName:@"http://baidu.com"];
    if ([reach currentReachabilityStatus] == NotReachable){
        block(NoNetwork);
    }else{
        block(NoServices);
    }
}

///读取双击文章功能打开还是关闭
+ (BOOL)isDoubleClickSwitch{
    NSString * document = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)firstObject];
    NSString * doubleClickSwitch = [document stringByAppendingPathComponent:@"doubleClickSwitchFile"];
    NSDictionary * okDic = [NSDictionary dictionaryWithContentsOfFile:doubleClickSwitch];
    if ([[okDic objectForKey:@"isONOrOff"] isEqualToString:@"ON"]) {
        return YES;
    }else if ([[okDic objectForKey:@"isONOrOff"] isEqualToString:@"OFF"]) {
        return NO;
    }else{
        return NO;
    }
}
+(NSString *)convert:(CGFloat)time{
    int minute = time / 60;
    int second = time - minute * 60;
    NSString *minuteString;
    NSString *secondString;
    if(minute < 10){
        minuteString = [NSString stringWithFormat:@"0%d", minute];
    }else{
        minuteString = [NSString stringWithFormat:@"%d", minute];
    }
    if(second < 10){
        secondString = [NSString stringWithFormat:@"0%d", second];
    }else{
        secondString = [NSString stringWithFormat:@"%d", second];
    }
    return [NSString stringWithFormat:@"%@:%@", minuteString, secondString];
}
+(CGFloat)caculateWidthOfText :(CGFloat)width height:(CGFloat)height font:(CGFloat)font :(NSString * )text
{
    //1.限制大小 2.绘制选项 3.属性（字号大小） 4.一般传nil
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:font]} context:nil];
    CGFloat whatHeight = ceilf(rect.size.width);
    return whatHeight+20;
}
 
@end
